<template>
  <view class="bg-gray" style="min-height:100vh">
    <view class="padding bg-white">
      <view class="padding-tb-lg"></view>
      <view class="text-center text-bold">唐山市第二医院新冠病毒核酸报告单</view>
      <view class="flex margin-top" style="line-height:1.5">
        <view style="width:40%">
          <view>身份证号：</view>
          <view>
            <text>姓名：</text>
            <text>{{reportData.uname}}</text>
          </view>
          <view>
            <text>科别：</text>
            <text>核酸检测门诊</text>
          </view>
          <view>
            样本种类：
          </view>
        </view>
        <view style="width:60%">
          <view>{{getMaskedIdNO(reportData.idnum)}}</view>
          <view class="flex">
            <view style="width:50%">
              <text>性别：</text>
              <text>{{getSexAsString(reportData.sex)}}</text>
            </view>
            <view style="width:50%">
              <text>年龄：</text>
              <text>{{getAgeFromIdNO(reportData.idnum)}}岁</text>
            </view>
          </view>
          <view>
            <text>送检医生：</text>
            <text></text>
          </view>
          <view>
            咽拭子-鼻咽拭子
          </view>
        </view>
      </view>
      
      <view class="margin-top flex" style="line-height:1.5">
        <view style="width:100px">
          <view class="padding-tb-xs bg-gray">代号</view>
          <!-- list -->
          <view v-for="(it,i) in checkList" :key="i">
            <text class="margin-right-sm">{{i + 1}}</text>
            <text>{{it.sub_code}}</text>
          </view>
        </view>
        <view style="flex:1">
          <view class="padding-tb-xs bg-gray">项目</view>
          <!-- list -->
          <view v-for="(it,i) in checkList" :key="i">{{it.sub_name}}</view>
        </view>
        <view style="width:50px">
          <view class="padding-tb-xs bg-gray">结果</view>
          <!-- list -->
          <view v-for="(it,i) in checkList" :key="i">{{it.ref_value}}</view>
        </view>
      </view>


      <view style="border-bottom:1px solid #e0e0e0;" class="text-right padding">
        <image :src="'/static/zhang.png'" style="width:120px;height:120px;"></image>
      </view>
      <view class="margin-top" style="line-height:1.5">
        <view>
          <text>采集时间：</text>
          <text class="margin-right">{{reportData.collect_time}}</text>

          <text>报告时间：</text>
          <text class="margin-right">{{reportData.report_time}}</text>

          <text>检验者：</text>
          <text class="margin-right"></text>

          <text>审核者：</text>
          <text class="margin-right"></text>

          <text>签收时间：</text>
          <text class="margin-right">{{reportData.intime}}</text>
        </view>
        <view>
          <text class="margin-right">如有疑问请联系检验科2058131</text> 
          <text>注：此检验报告仅对本标本负责</text>
        </view>
      </view>
    </view>

    <cu-bar></cu-bar>
  </view>
</template>

<script>
import moment from 'moment'
import CheckAuthMixin from '@/mixins/CheckAuthMixin'

const CACHE_KEY = 'ts_matters_submiting'

export default {
  mixins: [
    CheckAuthMixin,
  ],
  data() {
    return {
      submiting: false,
      reportData: {},
      checkList: [],
      sexOpts: [
        { label: '男', value: '1'},
        { label: '女', value: '2'},
      ],
      resultOpts: [
        { label: '阴性', value: '0' },
        { label: '疑似', value: '1' },
        { label: '阳性', value: '2' },
      ],
    }
  },
  watch: {
    submiting(val) {
      if (val) {
        uni.showLoading()
      } else {
        uni.hideLoading()
      }
    },
  },
  onLoad(opts) {
    const { orders_id } = opts
    this.$utils.pLog('=== orders_id: ', orders_id)
    
    this.loadState()

    this.$http({
      url: `/api/SampleResult/GetByOrderId?orders_id=${orders_id}`,
      method: 'POST',
      success: (res) => {
        if (res.success) {
          this.checkList = res.data
          // addr: "河北省唐山市"
          // birthday: "1992-07-25"
          // collect_time: "2022-05-15T11:08:34.71"
          // idnum: "130282199207255111"
          // intime: "2022-05-15T18:31:45"
          // item_value: "500copies/ml"
          // method: "实时荧光PCR"
          // oper_name: "检验管理员"
          // pat_id: 3
          // pat_name: "孟李辉"
          // ref_value: "阴性"
          // report_time: "2022-05-15T20:58:36"
          // res_id: 3
          // result: "0"
          // sample_id: 9
          // sex: "男"
          // sub_code: "ORFlab"
          // sub_name: "2019新型冠状病毒ORFlab基因"
          // tel: "15081515272"
          // type_id: 1
        } else {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          })
        }
      }
    })
  },
  methods: {
    getAgeFromIdNO(idno) {
      return Number(moment().format('YYYY')) - Number(idno.substring(6,10))
    },
    getMaskedIdNO(idno) {
      return idno.substring(0,4) + '***********' + idno.substring(idno.length-3)
    },
    getSexAsString(val) {
      return (this.sexOpts.find(x => x.value == val) || {}).label
    },
    loadState() {
      const cached = this.$utils.tempPageData.get('report_data')
      if (cached) {
        this.$utils.pLog('=== report data: ', cached)
        this.reportData = cached
      }
    },
  },
}
</script>

<style scoped>
.bg-cus-blue {
  background: #3182F8;
}
.no-bottom-border /deep/ .evan-form-item-container {
  border-bottom: none;
}
</style>